<?php
	include_once('dbcon.php');
	include_once('constants.php');
	include_once('error_log_db.php');
	include_once('general_functions_db.php');
	
	function get_best_content_db($limit, $user_id) {
		global $mysqli;
		
		$content_query = $mysqli->query("SELECT * FROM contents ORDER BY points DESC, content_id LIMIT ".$limit);
		logIfError($mysqli, $user_id, "contents_ranking_db", "get_best_content_db", "1");
		
		$all_content = array();

		while ($row = $content_query->fetch_assoc()) {
			
			$content = buildContentArray($row, -1);

			array_push($all_content, $content);
		}

		return json_encode($all_content, JSON_HEX_QUOT | JSON_HEX_APOS);
	}
	
	if ( isset($_REQUEST['limit']) && isset($_REQUEST['user_id']) ) {
		echo get_best_content_db($_REQUEST['limit'], $_REQUEST['user_id']);
	}
?>
